/*
 * @Author: WyvonJ 
 * @Date: 2018-04-18 16:22:05 
 * @Last Modified by: WyvonJ
 * @Last Modified time: 2018-04-25 15:59:35
 */
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  resolve: {
    modules: [path.join(__dirname, 'src'), 'node_modules'],
    extensions: ['.js', '.jsx', '.css', '.less', '.vue'],
    alias: {
      vue$: 'vue/dist/vue.js'
    }
  },
  context: path.join(__dirname, 'src'),
  entry: {
    app: ['./index.js']
  },
  output: {
    path: path.join(__dirname, 'build'),
    filename: '[name].[hash:5].js',
    publicPath: './',
    chunkFilename: '[name].js?[hash:8]'
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      mangle: true,
      compress: {
        warnings: false, // 生成warning
        drop_debugger: true,
        drop_console: true
      }
    }),
    new HtmlWebpackPlugin({
      template: './index.html', 
      filename: './index.html', 
      showErrors: true,
      inject: 'body',
      hash: true
    })
  ],
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css/,
        use: ['style-loader', 'css-loader', 'postcss-loader']
      },
      {
        test: /\.less/,
        use: [
          'style-loader',
          'css-loader',
          'postcss-loader',
          'autoprefixer-loader',
          'less-loader'
        ]
      },
      {
        test: /\.(png|jpg|gif|svg|eot|svg|ttf|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: '[path][name].[ext]'
        }
      }
    ]
  }
};
